package com.haibei.net;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import android.content.Context;

import com.common.net.FormFile;
import com.common.net.HttpRequester;
import com.common.net.NetException;
import com.common.net.NetResult;

public class NetInterface {

	private static final String base_path = "http://api.360haibei.com/";
	public static final String img_host = "http://img.360haibei.com/";

	// 包装图片的url
	public static String warpImgUrl(String imgUrl) {
		return img_host + imgUrl;
	}

	// 搜索商品
	public static NetResult searchTextGoods(Context context, HashMap<String, String> paramMap, int type) throws IOException, NetException,
			Exception {
		String path = "clientWare/search.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, path, paramMap);
		if (null != inputs) {
			if (1 == type) {
				return NetParser.parseArticle(inputs);
			} else {
				return NetParser.parseTopic(inputs);
			}
		}
		return null;
	}

	// 商品子评论
	public static NetResult addSubWareComment(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientWare/addSubComment.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseSubComment(inputs);
		}
		return null;
	}

	// 赞商品评论
	public static NetResult praiseGoods(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/praise.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrParse(inputs);
		}
		return null;
	}

	// 添加商品一级评论
	public static NetResult addParComments4Goods(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientWare/addParComment.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrComment1(inputs);
		}
		return null;
	}

	// 获取商品评论
	public static NetResult getGoodsComments(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/comments.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrComment2(inputs);
		}
		return null;
	}

	// 收藏商品
	public static NetResult collectGoods(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/addWare.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseCollectWare(inputs);
		}
		return null;
	}

	// 获取商品详情
	public static NetResult getGoodsDetail(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/detail.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseGoodsDetail(inputs);
		}
		return null;
	}

	// 获取所有商品
	public static NetResult listGoods(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/list.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseListGoods(inputs);
		}
		return null;
	}

	// 列出品牌
	public static NetResult listBrand(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/listBrand.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBrand(inputs);
		}
		return null;
	}

	// 列出产地
	public static NetResult listRegion(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/listRegion.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseRegion(inputs);
		}
		return null;
	}

	// 修改用户信息
	public static NetResult changeUserInfo(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/modify.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.modifyPassword(inputs);
		}
		return null;
	}

	/**
	 * 修改密码
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult modefyPasswd(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/modifyPassword.json?";
		// ServiceResult<User> loginResult =
		// userService.modifyPassword(username, oldPassword, newPassword);
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.modifyPassword(inputs);
		}
		return null;
	}

	/**
	 * 注册
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult regist(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/regist.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseRegist(inputs);
		}
		return null;
	}

	// 修改用户头像
	public static String modifyUserHeader(Context context, HashMap<String, String> paramMap, FormFile[] formFile) throws IOException,
			NetException, Exception {
		String path = "clientUser/modifyIconUpload.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		// FormFile formfile = new FormFile(imageFile.getName(), imageFile,
		// "image", "application/octet-stream");
		String result = HttpRequester.postUpload(base_path + path, paramMap, formFile);
		return result;
	}

	/**
	 * 登录
	 * 
	 * @param context
	 * @param paramMap
	 * @return
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult login(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/login.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseLogin(inputs);
		}
		return null;
	}

	/**
	 * 获取分类
	 * 
	 * @param context
	 * @param paramMap
	 * @return
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult getAriticleCategory(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientArticle/listCategory.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseArticleCategory(inputs);
		}
		return null;
	}

	/**
	 * 文章列表
	 * 
	 * @param context
	 * @param paramMap
	 * @return
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult getArticle(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientArticle/clientArticle/list.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseArticle(inputs);
		}
		return null;
	}

	/**
	 * 获取文章评论
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult getArticleDetail(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientArticle/detail.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrArticleDetail(inputs);
		}
		return null;
	}

	// 添加文章收藏
	public static NetResult collectArticle(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/addArticle.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseCollectArticle(inputs);
		}
		return null;
	}

	/**
	 * 添加评论
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult addComment(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientArticle/addParComment.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrComment1(inputs);
		}
		return null;
	}

	public static NetResult addSubComment(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientArticle/addSubComment.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseSubComment(inputs);
		}
		return null;
	}

	/**
	 * 获取所有评论
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult getArticleComments(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientArticle/comments.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrComment2(inputs);
		}
		return null;
	}

	/**
	 * 赞一个
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult praise(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientArticle/praise.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrParse(inputs);
		}
		return null;
	}

	/**
	 * 列举所有的话题
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult listTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientTopic/list.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseTopic(inputs);
		}
		return null;
	}

	public static NetResult detailTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientTopic/detail.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseDetailTopic(inputs);
		}
		return null;
	}

	/**
	 * 话题添加评论
	 * 
	 * @param context
	 * @param paramMap
	 * @return
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult addParComment4Topic(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientTopic/addParComment.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseCommentTopic(inputs);
		}
		return null;
	}

	public static NetResult getTopicComments(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientTopic/comments.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parsrComment2(inputs);
		}
		return null;
	}

	// 话题，子评论
	public static NetResult addSubTopicComment(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientTopic/addSubComment.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseSubComment(inputs);
		}
		return null;
	}

	// 话题，投票
	public static NetResult voteTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientTopic/vote.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseVoteTopic(inputs);
		}
		return null;
	}

	// 话题,投票,多选
	public static NetResult voteBatchTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientTopic/batchVote.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseVoteTopic(inputs);
		}
		return null;
	}

	public static NetResult collectTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/addTopic.json?";
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseVoteTopic(inputs);
		}
		return null;
	}

	/**
	 * 搜索
	 * 
	 * @param context
	 * @param paramMap
	 * @param type
	 * @return
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult searchText(Context context, HashMap<String, String> paramMap, int type) throws IOException, NetException,
			Exception {
		String path = "";
		if (1 == type) {
			path = "http://api.360haibei.com/clientArticle/search.html?";
		} else {
			path = "http://api.360haibei.com/clientTopic/search.html?";
		}
		// http://api.360haibei.com/clientArticle/search.html?searchText=%E9%98%B2%E8%BE%90%E5%B0%84&offset=0&limit=10
		// http://api.360haibei.com/clientTopic/search.html?searchText=%E9%98%B2%E8%BE%90%E5%B0%84&offset=0&limit=10
		// paramMap.putAll(NetTool.getCommonParam());
		InputStream inputs = HttpRequester.doSkyWorthPost(context, path, paramMap);
		if (null != inputs) {
			if (1 == type) {
				return NetParser.parseArticle(inputs);
			} else {
				return NetParser.parseTopic(inputs);
			}
		}
		return null;
	}

	// 搜索商品
	public static NetResult searchWareText(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = base_path + "clientWare/search.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, path, paramMap);
		if (null != inputs) {
			return NetParser.parseListGoods(inputs);
		}
		return null;
	}

	/**
	 * 商城首页的商品分类
	 * 
	 * @param context
	 * @param paramMap
	 * @throws IOException
	 * @throws NetException
	 * @throws Exception
	 */
	public static NetResult listParCategory(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/listParCategory.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseParCategory(inputs);
		}
		return null;
	}

	// 商城首页的广告列表
	public static NetResult listBanner(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientWare/listBanner.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBanner(inputs);
		}
		return null;
	}

	// 收藏的话题
	public static NetResult listCollectTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/listTopic.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseCollectTopic(inputs);
		}
		return null;
	}

	// 收藏的文章
	public static NetResult listCollectArticle(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientFavorite/listArticle.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseListCollectArticle(inputs);
		}
		return null;
	}

	// 收藏的商品
	public static NetResult listCollectWare(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/listWare.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseCollectWare(inputs);
		}
		return null;
	}

	// 消息中心
	public static NetResult listMessage(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/listMsg.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseListMessage(inputs);
		}
		return null;
	}

	// 批量删除收藏的文章
	public static NetResult batchRemoveArticle(Context context, HashMap<String, String> paramMap) throws IOException, NetException,
			Exception {
		String path = "clientFavorite/batchRemovArticle.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBatchRemove(inputs);
		}
		return null;
	}

	// 批量删除收藏的话题
	public static NetResult batchRemoveTopic(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/batchRemoveTopic.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBatchRemove(inputs);
		}
		return null;
	}

	// 批量删除收藏的商品
	public static NetResult batchRemoveWare(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientFavorite/batchRemoveWare.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBatchRemove(inputs);
		}
		return null;
	}

	// 批量删除消息
	public static NetResult batchRemoveMsg(Context context, HashMap<String, String> paramMap) throws IOException, NetException, Exception {
		String path = "clientUser/batchRemoveMsg.json?";
		InputStream inputs = HttpRequester.doSkyWorthPost(context, base_path + path, paramMap);
		if (null != inputs) {
			return NetParser.parseBatchRemove(inputs);
		}
		return null;
	}
}
